package Evento2;

import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Ventana extends JFrame implements ActionListener {
	private JPanel jp;
	private JLabel jl;
	private JButton jb1;
	private Receptora receptora;

	private void inicializar() {
		//Ventana
		setTitle("Dibujo");
		int ancho = Toolkit.getDefaultToolkit().getScreenSize().width;
		int alto = Toolkit.getDefaultToolkit().getScreenSize().height;
		int tAncho = 400;
		int tAlto = 400;
		setSize(tAncho, tAlto);
		setLocation((ancho / 2) - (tAncho / 2), (alto / 2) - (tAlto / 2));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(new GridLayout(1, 1));
		//Panel
		this.jp = new JPanel();
		this.add(jp);
		jp.setLayout(new GridLayout(2, 1));
		//JLabel
		this.jl = new JLabel("Mensaje");
		this.jp.add(jl);
		//JButton
		this.jb1 = new JButton("Saludar");
		this.jp.add(jb1);
		//Listener
		this.receptora = new Receptora(this.jl);
		jb1.addActionListener(receptora);
		jb1.addActionListener(this);
		
		setVisible(true);
	}

	public Ventana() {
		inicializar();
	}

	public static void main(String[] args) {
		new Ventana();
	}
	/**
	 * Le pedimos al JLabel que ponga el texto Hola
	 */
	public void actionPerformed(ActionEvent e) {
		jl.setText("Hola");
	}
}
